home *** CD-ROM | disk | FTP | other *** search
/ Languguage OS 2 / Languguage OS II Version 10-94 (Knowledge Media)(1994).ISO / gnu / nihcl-30.lha / nihcl-3.0 / lib / Template_c < prev    next >
Text File  |  1990-05-19  |  7KB  |  252 lines

  1. /* Template.c  -- example implementation of an NIH Library class
  2.  
  3.     THIS SOFTWARE FITS THE DESCRIPTION IN THE U.S. COPYRIGHT ACT OF A
  4.     "UNITED STATES GOVERNMENT WORK".  IT WAS WRITTEN AS A PART OF THE
  5.     AUTHOR'S OFFICIAL DUTIES AS A GOVERNMENT EMPLOYEE.  THIS MEANS IT
  6.     CANNOT BE COPYRIGHTED.  THIS SOFTWARE IS FREELY AVAILABLE TO THE
  7.     PUBLIC FOR USE WITHOUT A COPYRIGHT NOTICE, AND THERE ARE NO
  8.     RESTRICTIONS ON ITS USE, NOW OR SUBSEQUENTLY.
  9.  
  10. Author:
  11.     K. E. Gorlen
  12.     Bg. 12A, Rm. 2033
  13.     Computer Systems Laboratory
  14.     Division of Computer Research and Technology
  15.     National Institutes of Health
  16.     Bethesda, Maryland 20892
  17.     Phone: (301) 496-1111
  18.     uucp: uunet!nih-csl!kgorlen
  19.     Internet: kgorlen@alw.nih.gov
  20.     February, 1987
  21.  
  22. Function:
  23.     
  24. Modification History:
  25.  
  26. $Log:    Template_c,v $
  27. # Revision 3.0  90/05/20  00:21:40  kgorlen
  28. # Release for 1st edition.
  29. */
  30.  
  31. #include "THIS_CLASS.h"
  32. #include "nihclIO.h"
  33. // #include .h files for other classes used
  34.  
  35. #define    THIS    THIS_CLASS
  36. // Define BASE only for classes with one base class
  37. #define    BASE    BASE_CLASS
  38. // Define list of addresses of descriptors of all base classes:
  39. #define    BASE_CLASSES BASE::desc()
  40. // Define list of addresses of descriptors of all member classes:
  41. #define    MEMBER_CLASSES
  42. // Define list of addresses of descriptors of all virtual base
  43. // classes:
  44. #define VIRTUAL_BASE_CLASSES
  45.  
  46. DEFINE_CLASS(THIS_CLASS,1,"$Header: /afs/alw.nih.gov/unix/sun4_40c/usr/local/src/nihcl-3.0/share/lib/RCS/Template_c,v 3.0 90/05/20 00:21:40 kgorlen Rel $",NULL,NULL);
  47. // For abstract classes:
  48. //DEFINE_ABSTRACT_CLASS(THIS_CLASS,1,"$Header: /afs/alw.nih.gov/unix/sun4_40c/usr/local/src/nihcl-3.0/share/lib/RCS/Template_c,v 3.0 90/05/20 00:21:40 kgorlen Rel $",NULL,NULL);
  49. // For non-abstract classes with multiple base classes:
  50. //DEFINE_CLASS_MI(THIS_CLASS,1,"$Header: /afs/alw.nih.gov/unix/sun4_40c/usr/local/src/nihcl-3.0/share/lib/RCS/Template_c,v 3.0 90/05/20 00:21:40 kgorlen Rel $",NULL,NULL);
  51. // For abstract classes with multiple base classes:
  52. //DEFINE_ABSTRACT_CLASS_MI(THIS_CLASS,1,"$Header: /afs/alw.nih.gov/unix/sun4_40c/usr/local/src/nihcl-3.0/share/lib/RCS/Template_c,v 3.0 90/05/20 00:21:40 kgorlen Rel $",NULL,NULL);
  53.  
  54. extern const int // error codes
  55.  
  56. /* _castdown() for classes with multiple base classes:
  57.  
  58. void* THIS_CLASS::_castdown(const Class& target) const
  59. // (Probably a good candidate for memoization.)
  60. {
  61.     if (&target == desc()) return (void*)this;
  62.     void* p = BASE1::_castdown(target);
  63.     void* q = p;
  64.     if (p = BASE2::_castdown(target)) ambigCheck(p,q,target);
  65. // ...
  66.     if (p = BASEn::_castdown(target)) ambigCheck(p,q,target);
  67.     return q;
  68. }
  69.  
  70. */
  71.  
  72. bool THIS_CLASS::operator==(const THIS_CLASS& a) const
  73. // Test two instances of THIS_CLASS for equality
  74. {
  75. }
  76.  
  77. const Class* THIS_CLASS::species() const
  78. // Return a pointer to the descriptor of the species of this class
  79. {
  80.     return &classDesc;
  81. }
  82.  
  83. bool THIS_CLASS::isEqual(const Object& p) const
  84. // Test two objects for equality
  85. {
  86.     return p.isSpecies(classDesc) && *this==castdown(p);
  87. }
  88.  
  89. unsigned THIS_CLASS::hash() const
  90. // If two objects are equal (i.e., isEqual) they must have
  91. // the same hash
  92. {
  93. }
  94.  
  95. int THIS_CLASS::compare(const Object& p) const
  96. // Compare two objects.  If *this > p return >0,
  97. // *this == p return 0, and if *this < p return <0.
  98. {
  99.     assertArgSpecies(p,classDesc,"compare");
  100. }
  101.  
  102. void THIS_CLASS::deepenShallowCopy()
  103. // Called by deepCopy() to convert a shallow copy to a deep copy.
  104. // deepCopy() makes the shallow copy by calling the copy
  105. // constructor.
  106. {
  107. /*
  108. Deepen base classes in order specified in class declaration.
  109.  
  110. Deepen virtual base classes (VBase):
  111.     VBase::deepenVBase();        // do not do this for class Object
  112.  
  113. Deepen non-virtual base classes (BASE):
  114.     BASE::deepenShallowCopy();    // do not do this for class Object
  115.  
  116. Nothing need be done for member variables that are fundamental
  117. types.  Copy a member variable o that is an NIHCL object:
  118.     o.deepenShallowCopy();
  119.  
  120. Copy a member variable p that is a pointer to an NIHCL object of
  121. class CLASS:
  122.     p = (CLASS*)p->deepCopy();
  123. */
  124. }
  125.  
  126. void THIS_CLASS::printOn(ostream& strm) const
  127. // Print this object on an ostream
  128. {
  129. }
  130.  
  131. // Object I/O
  132.  
  133. /*
  134. Member class instances are constructed in the order they are
  135. declared in the class declaration, regardless of the order they
  136. appear in the constructor initialization list, so they must be
  137. stored in this order.  Note that member class instances are
  138. constructed before body of constructor is executed.
  139. */
  140.  
  141. // Construct an object from OIOin "strm".
  142. THIS_CLASS::THIS_CLASS(OIOin& strm)
  143. :
  144. #ifdef MI
  145.     Object(strm),
  146. #endif
  147. /*
  148. Call readFrom() constructors of all ancestor virtual base classes:
  149.     VBase(strm),
  150. */
  151.     BASE(strm)
  152. /*
  153. Read a member variable o that is an instance of an NIHCL class:
  154.     o(strm)
  155. {
  156. Read a member variable f that is a fundamental type using ">>":
  157.     strm >> f;
  158.  
  159. Read a member variable p that is a pointer to an instance of
  160. the NIHCL class CLASS:
  161.     p = CLASS::readFrom(strm);
  162.  
  163. Read member variables in the same order that they are stored.
  164. */
  165. }
  166.  
  167. void THIS_CLASS::storer(OIOout& strm) const
  168. // Store the member variables of this object on OIOout "strm".
  169. {
  170. /*
  171. Store virtual base classes (VBase) in inheritance DAG order:
  172.     VBase::storeVBaseOn(strm);
  173.  
  174. Store non-virtual base classes in order specified in class
  175. declaration:
  176.     BASE::storer(strm);
  177.  
  178. Store a member variable f that is a fundamental type using "<<":
  179.     strm << f;
  180.  
  181. Store a member variable o that is an instance of the NIHCL class
  182. CLASS:
  183.     o.storeMemberOn(strm);
  184.  
  185. Store a member variable p that is a pointer to an instance of an
  186. NIHCL class:
  187.     p->storeOn(strm);
  188.  
  189. Store member variables in the same order that they are read.
  190. */
  191. }
  192.  
  193. // Construct an object from file descriptor "fd".
  194. THIS_CLASS::THIS_CLASS(OIOifd& fd)
  195. :
  196. #ifdef MI
  197.     Object(fd),
  198. #endif
  199. /*
  200. Call readFrom() constructors of all ancestor virtual base classes:
  201.     VBase(fd),
  202. */
  203.     BASE(fd)
  204. /*
  205. Read a member variable o that is an instance of an NIHCL class:
  206.     o(fd)
  207. {
  208. Read a member variable f that is a fundamental type:
  209.     fd >> f;
  210.  
  211. Read a member variable a that is a pointer to an array of length l:
  212.     fd.get(a,l);
  213.  
  214. Read a member variable p that is a pointer to an instance of the
  215. NIHCL class CLASS:
  216.     p = CLASS::readFrom(fd);
  217.  
  218. Read member variables in the same order that they are stored.
  219. */
  220. }
  221.  
  222. void THIS_CLASS::storer(OIOofd& fd) const
  223. // Store an object on file descriptor "fd".
  224. {
  225. /*
  226. Store virtual base classes (VBase) in inheritance DAG order:
  227.     VBase::storeVBaseOn(fd);
  228.  
  229. Store non-virtual base classes in order specified in class
  230. declaration:
  231.     BASE::storer(fd);
  232.  
  233. Store a member variable f that is a fundamental type:
  234.     fd << f;
  235.  
  236. Store a member variable a that is a pointer to an array
  237. of length l:
  238.     fd.put(a,l);
  239.  
  240. Store a member variable o that is an instance of the NIHCL class
  241. CLASS:
  242.     o.storeMemberOn(fd);
  243.  
  244. Store a member variable p that is a pointer to an instance of an
  245. NIHCL class:
  246.     p->storeOn(fd);
  247.  
  248. Store member variables in the same order that they are read.
  249. */
  250. }
  251.